﻿using STHPMS1.DAL.D_Core;
using System.Data;
using ServiceStack.OrmLite;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore.I_DAL.Repository;
using System.Collections.Generic;
namespace STHPMS1.DAL.D_Repository
{
    public class Dp_Preven_DetailRepository : DalBase, IDp_Preven_DetailRepository
    {
        /// <summary>
        /// 获取分析年度的所有养护路段
        /// </summary>
        /// <param name="rdwayid"></param>
        /// <returns></returns>
        public List<string> GetMainSegid(string anniname, string analy_year)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select distinct MAINSEGID from  [DP_PREVEN_DETAIL] where ANNI_NAME='" + anniname + "' AND ANALY_YEAR='" + analy_year + "'";
            return conn.Column<string>(strsql);
        }

        ///// <summary>
        ///// 更新等效年度费用
        ///// </summary>
        ///// <param name="rdwayid"></param>
        //public void SetEAC(string analy_year)
        //{
        //    IDbConnection conn = Adapter.OpenDbConnection();
        //    conn.ExecuteNonQuery("update [DP_PREVEN_DETAIL] set [EAC]=[UNIT_COST]/[SERVI_LIFE]  where [ANALY_YEAR]='" + analy_year + "'");
        //}

        /// <summary>
        /// 更新复选措施 设置为1
        /// </summary>
        /// <param name="rdwayid"></param>
        /// <param name="mainsegid"></param>
        /// <param name="values"></param>
        public void SetSECON_MEASURE(string anniname, string analy_year, string mainsegid, int values)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "update [DP_PREVEN_DETAIL] set SECON_MEASURE=" + values + " where ID in(select top 3 id from [DP_PREVEN_DETAIL] where ANNI_NAME='" + anniname + "' AND ANALY_YEAR='" + analy_year + "' and  [MAINSEGID]='" + mainsegid + "' order by EAC asc)";
            conn.ExecuteNonQuery(strsql);

        }
       

       

        /// <summary>
        /// 获取养护年份 复选措施和终选措施都为1
        /// </summary>
        /// <param name="mainsegid"></param>
        /// <returns></returns>
        public string GetMainYear(string mainsegid)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select MAIN_YEAR from DP_PREVEN_DETAIL where MAINSEGID='" + mainsegid + "' and SECON_MEASURE=1 and PREVEN_MEASURE=1";
            return conn.Scalar<string>(strsql);
        }

        /// <summary>
        /// 获取总费用 复选措施和终选措施都为1
        /// </summary>
        /// <param name="mainsegid"></param>
        /// <returns></returns>
        public double GetCost(string mainsegid)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select COST from DP_PREVEN_DETAIL where MAINSEGID='" + mainsegid + "' and SECON_MEASURE=1 and PREVEN_MEASURE=1 ";
            return conn.Scalar<double>(strsql);
        }

        /// <summary>
        /// 获取当前路线的所有初选措施
        /// </summary>
        /// <param name="rdwayid"></param>
        /// <returns></returns>
        public List<string> GetMeas_ini(string rdwayid)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select distinct MEAS_INI from DP_PREVEN_DETAIL where RDWAYID='G6001' and SECON_MEASURE=1";
            return conn.Column<string>(strsql);
        }
        
      
    }
}
